* This file prepares main tables for 'Benchmarking Intensity'

* Specifically, the output includes Table 5
* Please refer to variable labels in the sample data for the input description

********************************************************************************
*** Load 
clear all
use sample_june_ret.dta, clear

gen lmv = log(total_mv)
gen band = 0
replace band = 1 if rank > c1 & rank < c2
gen band_d2 = 0
replace band_d2 = band*d02 

* choose band width
gen dist = 300

* set up the band width filter
gen filter = 0
replace filter = 1 if (abs(dist_up)<=dist | abs(dist_down)<=dist) 

* generate benchmark changes
gen d12 = 0
gen d21 = 0
replace d12 = 1 if d01 == 1 & d2 == 1
replace d21 = 1 if d02 == 1 & d1 == 1
label var d12 "D(Russell 1000 $\rightarrow$ Russell 2000)"
label var d21 "D(Russell 2000 $\rightarrow$ Russell 1000)"


* generate ownership changes
xtset PERMNO year
foreach x of varlist own_ru1_active own_ru2_active own_ru1_passive own_ru2_passive own_mc_active own_mc_passive {
	replace `x' = `x'*100
	replace `x'_mar = `x'_mar*100
	keep if `x' <= 100
	keep if `x'_mar <= 100
	
	* change in ownership share
	gen delm_`x' = `x' - `x'_mar
	replace delm_`x' = -`x'_mar if `x' == .
	replace delm_`x' = `x' if `x'_mar == .
	
	* holding status
	gen d_`x' = 0
	replace d_`x' = 1 if `x' > 0
	gen d_`x'_mar = 0
	replace d_`x'_mar = 1 if `x'_mar > 0
	
	* change in holding status
	gen tcm_`x' = 0
	replace tcm_`x' = 1 if delm_`x' > 0 
	replace tcm_`x' = -1 if delm_`x' < 0 
	
}

global controls_band " lmv ff_rus wcapm_beta ba_spread band d02 band_d2 "
global controls_no_band " lmv ff_rus wcapm_beta ba_spread "




********************************************************************************
*** Produce panels of Table 5

**** Produce Panel A

foreach x of varlist own_ru1_active own_ru1_passive own_mc_active own_mc_passive own_ru2_active own_ru2_passive  {

	reghdfe delm_`x' d21 d12 $controls_no_band if filter == 1, absorb( year) cl(PERMNO year) 

}
	
	
**** Produce Panel B

foreach x of varlist own_ru1_active own_ru1_passive own_mc_active own_mc_passive own_ru2_active own_ru2_passive  {

	reghdfe tcm_`x' d21 d12 $controls_no_band if filter == 1, absorb(year) cl(PERMNO year)

}


**** Produce Panel C

foreach x of varlist own_ru1_active own_ru1_passive own_mc_active own_mc_passive own_ru2_active own_ru2_passive  {

	reghdfe `x' d2  $controls_band `x'_mar if filter == 1, absorb( year) cl(PERMNO year)

}


**** Produce Panel D
foreach x of varlist own_ru1_active own_ru1_passive own_mc_active own_mc_passive own_ru2_active own_ru2_passive  {

	reghdfe d_`x' d2 $controls_band d_`x'_mar if filter == 1, absorb( year) cl(PERMNO year)

}


